{
 "cells": [
  {
   "cell_type": "code",
   "execution_count": 1,
   "metadata": {},
   "outputs": [
    {
     "name": "stderr",
     "output_type": "stream",
     "text": [
      "C:\\Users\\Administrator\\Anaconda3\\lib\\requests\\__init__.py:80: RequestsDependencyWarning: urllib3 (1.25.11) or chardet (3.0.4) doesn't match a supported version!\n",
      "  RequestsDependencyWarning)\n"
     ]
    },
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "matchzoo version 1.0.2\n",
      "`ranking_task` initialized with metrics [normalized_discounted_cumulative_gain@3(0.0), normalized_discounted_cumulative_gain@5(0.0), mean_average_precision(0.0)]\n",
      "data loading ...\n",
      "data loaded as `train_pack_raw` `dev_pack_raw` `test_pack_raw`\n",
      "停用表配置成功\n"
     ]
    }
   ],
   "source": [
    "%run init.ipynb"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 2,
   "metadata": {
    "collapsed": true
   },
   "outputs": [],
   "source": [
    "preprocessor = mz.models.CDSSM.get_default_preprocessor(\n",
    "    ngram_size = 3\n",
    ")"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 3,
   "metadata": {},
   "outputs": [
    {
     "name": "stderr",
     "output_type": "stream",
     "text": [
      "Processing text_left with chain_transform of ChineseRemoveBlack => ChineseSimplified => ChineseEmotion => IsChinese => ChineseStopRemoval => ChineseTokenizeDemo => Tokenize => Lowercase => PuncRemoval:   0%| | 0/95 [00:00<?, ?it/s]Building prefix dict from the default dictionary ...\n",
      "Loading model from cache C:\\Users\\ADMINI~1\\AppData\\Local\\Temp\\jieba.cache\n",
      "Loading model cost 2.607 seconds.\n",
      "Prefix dict has been built succesfully.\n",
      "Processing text_left with chain_transform of ChineseRemoveBlack => ChineseSimplified => ChineseEmotion => IsChinese => ChineseStopRemoval => ChineseTokenizeDemo => Tokenize => Lowercase => PuncRemoval: 100%|█| 95/95 [00:03<00:00, 27.35it/s]\n",
      "Processing text_right with chain_transform of ChineseRemoveBlack => ChineseSimplified => ChineseEmotion => IsChinese => ChineseStopRemoval => ChineseTokenizeDemo => Tokenize => Lowercase => PuncRemoval: 100%|█| 97/97 [00:00<00:00, 127.88it/s]\n",
      "Processing text_right with append: 100%|████████████████████████████████████████████| 97/97 [00:00<00:00, 96983.91it/s]\n",
      "Building FrequencyFilter from a datapack.: 100%|████████████████████████████████████| 97/97 [00:00<00:00, 19413.44it/s]\n",
      "Processing text_right with transform: 100%|█████████████████████████████████████████| 97/97 [00:00<00:00, 24244.53it/s]\n",
      "Processing text_left with extend: 100%|█████████████████████████████████████████████| 95/95 [00:00<00:00, 95097.58it/s]\n",
      "Processing text_right with extend: 100%|████████████████████████████████████████████| 97/97 [00:00<00:00, 48515.08it/s]\n",
      "Building Vocabulary from a datapack.: 100%|██████████████████████████████████████| 879/879 [00:00<00:00, 880323.12it/s]\n",
      "Processing text_left with transform: 100%|██████████████████████████████████████████| 95/95 [00:00<00:00, 19005.91it/s]\n",
      "Processing text_right with transform: 100%|█████████████████████████████████████████| 97/97 [00:00<00:00, 12131.30it/s]\n",
      "Processing text_left with extend: 100%|█████████████████████████████████████████████| 95/95 [00:00<00:00, 31658.90it/s]\n",
      "Processing text_right with extend: 100%|████████████████████████████████████████████| 97/97 [00:00<00:00, 24253.20it/s]\n",
      "Building Vocabulary from a datapack.: 100%|██████████████████████████████████████| 879/879 [00:00<00:00, 292765.28it/s]\n",
      "Processing text_left with chain_transform of ChineseRemoveBlack => ChineseSimplified => ChineseEmotion => IsChinese => ChineseStopRemoval => ChineseTokenizeDemo => Tokenize => Lowercase => PuncRemoval: 100%|█| 95/95 [00:00<00:00, 135.41it/s]\n",
      "Processing text_right with chain_transform of ChineseRemoveBlack => ChineseSimplified => ChineseEmotion => IsChinese => ChineseStopRemoval => ChineseTokenizeDemo => Tokenize => Lowercase => PuncRemoval: 100%|█| 97/97 [00:00<00:00, 128.21it/s]\n",
      "Processing text_right with transform: 100%|█████████████████████████████████████████| 97/97 [00:00<00:00, 97192.42it/s]\n",
      "Processing text_left with transform: 100%|██████████████████████████████████████████| 95/95 [00:00<00:00, 15841.41it/s]\n",
      "Processing text_right with transform: 100%|█████████████████████████████████████████| 97/97 [00:00<00:00, 24264.78it/s]\n",
      "Processing length_left with len: 100%|██████████████████████████████████████████████| 95/95 [00:00<00:00, 95370.72it/s]\n",
      "Processing length_right with len: 100%|█████████████████████████████████████████████| 97/97 [00:00<00:00, 32340.82it/s]\n",
      "Processing text_left with chain_transform of ChineseRemoveBlack => ChineseSimplified => ChineseEmotion => IsChinese => ChineseStopRemoval => ChineseTokenizeDemo => Tokenize => Lowercase => PuncRemoval: 100%|█| 47/47 [00:00<00:00, 136.71it/s]\n",
      "Processing text_right with chain_transform of ChineseRemoveBlack => ChineseSimplified => ChineseEmotion => IsChinese => ChineseStopRemoval => ChineseTokenizeDemo => Tokenize => Lowercase => PuncRemoval: 100%|█| 50/50 [00:00<00:00, 140.53it/s]\n",
      "Processing text_right with transform: 100%|█████████████████████████████████████████| 50/50 [00:00<00:00, 49979.79it/s]\n",
      "Processing text_left with transform: 100%|██████████████████████████████████████████| 47/47 [00:00<00:00, 11771.20it/s]\n",
      "Processing text_right with transform: 100%|██████████████████████████████████████████| 50/50 [00:00<00:00, 7146.30it/s]\n",
      "Processing length_left with len: 100%|███████████████████████████████████████████████| 47/47 [00:00<00:00, 6717.52it/s]\n",
      "Processing length_right with len: 100%|█████████████████████████████████████████████| 50/50 [00:00<00:00, 24983.94it/s]\n",
      "Processing text_left with chain_transform of ChineseRemoveBlack => ChineseSimplified => ChineseEmotion => IsChinese => ChineseStopRemoval => ChineseTokenizeDemo => Tokenize => Lowercase => PuncRemoval: 100%|█| 30/30 [00:00<00:00, 114.57it/s]\n",
      "Processing text_right with chain_transform of ChineseRemoveBlack => ChineseSimplified => ChineseEmotion => IsChinese => ChineseStopRemoval => ChineseTokenizeDemo => Tokenize => Lowercase => PuncRemoval: 100%|█| 29/29 [00:00<00:00, 83.62it/s] \n",
      "Processing text_right with transform: 100%|██████████████████████████████████████████| 29/29 [00:00<00:00, 9678.14it/s]\n",
      "Processing text_left with transform: 100%|██████████████████████████████████████████| 30/30 [00:00<00:00, 30009.33it/s]\n",
      "Processing text_right with transform: 100%|██████████████████████████████████████████| 29/29 [00:00<00:00, 9700.52it/s]\n",
      "Processing length_left with len: 100%|██████████████████████████████████████████████| 30/30 [00:00<00:00, 10015.85it/s]\n",
      "Processing length_right with len: 100%|█████████████████████████████████████████████| 29/29 [00:00<00:00, 14490.69it/s]\n"
     ]
    }
   ],
   "source": [
    "train_pack_processed = preprocessor.fit_transform(train_pack_raw)\n",
    "dev_pack_processed = preprocessor.transform(dev_pack_raw)\n",
    "test_pack_processed = preprocessor.transform(test_pack_raw)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 4,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "{'embedding_input_dim': 307,\n",
       " 'filter_unit': <mzcn.preprocessors.units.frequency_filter.FrequencyFilter at 0x1af4c9dfb00>,\n",
       " 'ngram_process_unit': <mzcn.preprocessors.units.ngram_letter.NgramLetter at 0x1af5a4fcbe0>,\n",
       " 'ngram_vocab_size': 307,\n",
       " 'ngram_vocab_unit': <mzcn.preprocessors.units.vocabulary.Vocabulary at 0x1af5a6f9cc0>,\n",
       " 'vocab_size': 307,\n",
       " 'vocab_unit': <mzcn.preprocessors.units.vocabulary.Vocabulary at 0x1af5a6f4a58>}"
      ]
     },
     "execution_count": 4,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "preprocessor.context"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 5,
   "metadata": {
    "collapsed": true
   },
   "outputs": [],
   "source": [
    "triletter_callback = mz.dataloader.callbacks.Ngram(preprocessor, mode='sum')\n",
    "trainset = mz.dataloader.Dataset(\n",
    "    data_pack=train_pack_processed,\n",
    "    mode='pair',\n",
    "    num_dup=2,\n",
    "    num_neg=1,\n",
    "    callbacks=[triletter_callback]\n",
    ")\n",
    "devset = mz.dataloader.Dataset(\n",
    "    data_pack=dev_pack_processed,\n",
    "    callbacks=[triletter_callback]\n",
    ")"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 6,
   "metadata": {
    "collapsed": true
   },
   "outputs": [],
   "source": [
    "padding_callback = mz.models.CDSSM.get_default_padding_callback(\n",
    "    with_ngram=True,\n",
    "    fixed_ngram_length=preprocessor.context['ngram_vocab_size']\n",
    ")\n",
    "\n",
    "trainloader = mz.dataloader.DataLoader(\n",
    "    dataset=trainset,\n",
    "    stage='train',\n",
    "    callback=padding_callback,\n",
    ")\n",
    "devloader = mz.dataloader.DataLoader(\n",
    "    dataset=devset,\n",
    "    stage='dev',\n",
    "    callback=padding_callback,\n",
    ")"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 7,
   "metadata": {
    "scrolled": false
   },
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "CDSSM(\n",
      "  (net_left): Sequential(\n",
      "    (0): ConstantPad1d(padding=(0, 2), value=0)\n",
      "    (1): Conv1d(307, 64, kernel_size=(3,), stride=(1,))\n",
      "    (2): Tanh()\n",
      "    (3): Dropout(p=0.8, inplace=False)\n",
      "    (4): AdaptiveMaxPool1d(output_size=1)\n",
      "    (5): Squeeze()\n",
      "    (6): Sequential(\n",
      "      (0): Sequential(\n",
      "        (0): Linear(in_features=64, out_features=64, bias=True)\n",
      "        (1): Tanh()\n",
      "      )\n",
      "      (1): Sequential(\n",
      "        (0): Linear(in_features=64, out_features=64, bias=True)\n",
      "        (1): Tanh()\n",
      "      )\n",
      "    )\n",
      "  )\n",
      "  (net_right): Sequential(\n",
      "    (0): ConstantPad1d(padding=(0, 2), value=0)\n",
      "    (1): Conv1d(307, 64, kernel_size=(3,), stride=(1,))\n",
      "    (2): Tanh()\n",
      "    (3): Dropout(p=0.8, inplace=False)\n",
      "    (4): AdaptiveMaxPool1d(output_size=1)\n",
      "    (5): Squeeze()\n",
      "    (6): Sequential(\n",
      "      (0): Sequential(\n",
      "        (0): Linear(in_features=64, out_features=64, bias=True)\n",
      "        (1): Tanh()\n",
      "      )\n",
      "      (1): Sequential(\n",
      "        (0): Linear(in_features=64, out_features=64, bias=True)\n",
      "        (1): Tanh()\n",
      "      )\n",
      "    )\n",
      "  )\n",
      "  (out): Linear(in_features=1, out_features=1, bias=True)\n",
      ")\n",
      "Trainable params:  134658\n"
     ]
    }
   ],
   "source": [
    "model = mz.models.CDSSM()\n",
    "\n",
    "model.params['task'] = ranking_task\n",
    "model.params['vocab_size'] = preprocessor.context['ngram_vocab_size']\n",
    "model.params['filters'] = 64\n",
    "model.params['kernel_size'] = 3\n",
    "model.params['conv_activation_func'] = 'tanh'\n",
    "model.params['mlp_num_layers'] = 1\n",
    "model.params['mlp_num_units'] = 64\n",
    "model.params['mlp_num_fan_out'] = 64\n",
    "model.params['mlp_activation_func'] = 'tanh'\n",
    "model.params['dropout_rate'] = 0.8\n",
    "\n",
    "model.build()\n",
    "\n",
    "print(model)\n",
    "print('Trainable params: ', sum(p.numel() for p in model.parameters() if p.requires_grad))"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 8,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "application/vnd.jupyter.widget-view+json": {
       "model_id": "01d0e36fabd34192899f1956c155b40e",
       "version_major": 2,
       "version_minor": 0
      },
      "text/plain": [
       "HBox(children=(IntProgress(value=0, max=1), HTML(value='')))"
      ]
     },
     "metadata": {},
     "output_type": "display_data"
    },
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "[Iter-1 Loss-1.040]:\n",
      "  Validation: normalized_discounted_cumulative_gain@3(0.0): 0.2647 - normalized_discounted_cumulative_gain@5(0.0): 0.2647 - mean_average_precision(0.0): 0.2647\n",
      "\n"
     ]
    },
    {
     "data": {
      "application/vnd.jupyter.widget-view+json": {
       "model_id": "cb995938353940228a4af0e5c34bd5d7",
       "version_major": 2,
       "version_minor": 0
      },
      "text/plain": [
       "HBox(children=(IntProgress(value=0, max=1), HTML(value='')))"
      ]
     },
     "metadata": {},
     "output_type": "display_data"
    },
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "[Iter-2 Loss-1.061]:\n",
      "  Validation: normalized_discounted_cumulative_gain@3(0.0): 0.2647 - normalized_discounted_cumulative_gain@5(0.0): 0.2647 - mean_average_precision(0.0): 0.2647\n",
      "\n"
     ]
    },
    {
     "data": {
      "application/vnd.jupyter.widget-view+json": {
       "model_id": "8486fd2e611448629633141b75cfc6a8",
       "version_major": 2,
       "version_minor": 0
      },
      "text/plain": [
       "HBox(children=(IntProgress(value=0, max=1), HTML(value='')))"
      ]
     },
     "metadata": {},
     "output_type": "display_data"
    },
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "[Iter-3 Loss-0.983]:\n",
      "  Validation: normalized_discounted_cumulative_gain@3(0.0): 0.2647 - normalized_discounted_cumulative_gain@5(0.0): 0.2647 - mean_average_precision(0.0): 0.2647\n",
      "\n"
     ]
    },
    {
     "data": {
      "application/vnd.jupyter.widget-view+json": {
       "model_id": "b2b8c277cece422fb4b11489044eeabb",
       "version_major": 2,
       "version_minor": 0
      },
      "text/plain": [
       "HBox(children=(IntProgress(value=0, max=1), HTML(value='')))"
      ]
     },
     "metadata": {},
     "output_type": "display_data"
    },
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "[Iter-4 Loss-0.999]:\n",
      "  Validation: normalized_discounted_cumulative_gain@3(0.0): 0.2647 - normalized_discounted_cumulative_gain@5(0.0): 0.2647 - mean_average_precision(0.0): 0.2647\n",
      "\n"
     ]
    },
    {
     "data": {
      "application/vnd.jupyter.widget-view+json": {
       "model_id": "6a5fffb426754876babcf9518938753a",
       "version_major": 2,
       "version_minor": 0
      },
      "text/plain": [
       "HBox(children=(IntProgress(value=0, max=1), HTML(value='')))"
      ]
     },
     "metadata": {},
     "output_type": "display_data"
    },
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "[Iter-5 Loss-0.996]:\n",
      "  Validation: normalized_discounted_cumulative_gain@3(0.0): 0.2647 - normalized_discounted_cumulative_gain@5(0.0): 0.2647 - mean_average_precision(0.0): 0.2647\n",
      "\n"
     ]
    },
    {
     "data": {
      "application/vnd.jupyter.widget-view+json": {
       "model_id": "ea2fa1218e5f41e0ba32f704790411e3",
       "version_major": 2,
       "version_minor": 0
      },
      "text/plain": [
       "HBox(children=(IntProgress(value=0, max=1), HTML(value='')))"
      ]
     },
     "metadata": {},
     "output_type": "display_data"
    },
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "[Iter-6 Loss-1.046]:\n",
      "  Validation: normalized_discounted_cumulative_gain@3(0.0): 0.2647 - normalized_discounted_cumulative_gain@5(0.0): 0.2647 - mean_average_precision(0.0): 0.2647\n",
      "\n"
     ]
    },
    {
     "data": {
      "application/vnd.jupyter.widget-view+json": {
       "model_id": "42044118bba84516a288a8e9e2cf90f3",
       "version_major": 2,
       "version_minor": 0
      },
      "text/plain": [
       "HBox(children=(IntProgress(value=0, max=1), HTML(value='')))"
      ]
     },
     "metadata": {},
     "output_type": "display_data"
    },
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "[Iter-7 Loss-0.971]:\n",
      "  Validation: normalized_discounted_cumulative_gain@3(0.0): 0.2647 - normalized_discounted_cumulative_gain@5(0.0): 0.2647 - mean_average_precision(0.0): 0.2647\n",
      "\n"
     ]
    },
    {
     "data": {
      "application/vnd.jupyter.widget-view+json": {
       "model_id": "cde61acb5bff4c6bb3d52a470efe3442",
       "version_major": 2,
       "version_minor": 0
      },
      "text/plain": [
       "HBox(children=(IntProgress(value=0, max=1), HTML(value='')))"
      ]
     },
     "metadata": {},
     "output_type": "display_data"
    },
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "[Iter-8 Loss-0.911]:\n",
      "  Validation: normalized_discounted_cumulative_gain@3(0.0): 0.2647 - normalized_discounted_cumulative_gain@5(0.0): 0.2647 - mean_average_precision(0.0): 0.2647\n",
      "\n"
     ]
    },
    {
     "data": {
      "application/vnd.jupyter.widget-view+json": {
       "model_id": "b555d6adbecf48f996611a6c780fc267",
       "version_major": 2,
       "version_minor": 0
      },
      "text/plain": [
       "HBox(children=(IntProgress(value=0, max=1), HTML(value='')))"
      ]
     },
     "metadata": {},
     "output_type": "display_data"
    },
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "[Iter-9 Loss-0.943]:\n",
      "  Validation: normalized_discounted_cumulative_gain@3(0.0): 0.2647 - normalized_discounted_cumulative_gain@5(0.0): 0.2647 - mean_average_precision(0.0): 0.2647\n",
      "\n"
     ]
    },
    {
     "data": {
      "application/vnd.jupyter.widget-view+json": {
       "model_id": "66ca173173ef4c0a811b9ae7768c348e",
       "version_major": 2,
       "version_minor": 0
      },
      "text/plain": [
       "HBox(children=(IntProgress(value=0, max=1), HTML(value='')))"
      ]
     },
     "metadata": {},
     "output_type": "display_data"
    },
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "[Iter-10 Loss-1.036]:\n",
      "  Validation: normalized_discounted_cumulative_gain@3(0.0): 0.2647 - normalized_discounted_cumulative_gain@5(0.0): 0.2647 - mean_average_precision(0.0): 0.2647\n",
      "\n"
     ]
    },
    {
     "data": {
      "application/vnd.jupyter.widget-view+json": {
       "model_id": "b91762cca9ea47f69bbaa7e8ec15c315",
       "version_major": 2,
       "version_minor": 0
      },
      "text/plain": [
       "HBox(children=(IntProgress(value=0, max=1), HTML(value='')))"
      ]
     },
     "metadata": {},
     "output_type": "display_data"
    },
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "[Iter-11 Loss-1.034]:\n",
      "  Validation: normalized_discounted_cumulative_gain@3(0.0): 0.2647 - normalized_discounted_cumulative_gain@5(0.0): 0.2647 - mean_average_precision(0.0): 0.2647\n",
      "\n"
     ]
    },
    {
     "data": {
      "application/vnd.jupyter.widget-view+json": {
       "model_id": "98e90bf89d3e4084b99bffcfcdeac55d",
       "version_major": 2,
       "version_minor": 0
      },
      "text/plain": [
       "HBox(children=(IntProgress(value=0, max=1), HTML(value='')))"
      ]
     },
     "metadata": {},
     "output_type": "display_data"
    },
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "[Iter-12 Loss-0.980]:\n",
      "  Validation: normalized_discounted_cumulative_gain@3(0.0): 0.2647 - normalized_discounted_cumulative_gain@5(0.0): 0.2647 - mean_average_precision(0.0): 0.2647\n",
      "\n"
     ]
    },
    {
     "data": {
      "application/vnd.jupyter.widget-view+json": {
       "model_id": "0bc4dfa0aacd40eba9b9f993f4e36d13",
       "version_major": 2,
       "version_minor": 0
      },
      "text/plain": [
       "HBox(children=(IntProgress(value=0, max=1), HTML(value='')))"
      ]
     },
     "metadata": {},
     "output_type": "display_data"
    },
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "[Iter-13 Loss-0.971]:\n",
      "  Validation: normalized_discounted_cumulative_gain@3(0.0): 0.2647 - normalized_discounted_cumulative_gain@5(0.0): 0.2647 - mean_average_precision(0.0): 0.2647\n",
      "\n"
     ]
    },
    {
     "data": {
      "application/vnd.jupyter.widget-view+json": {
       "model_id": "4c1e12171e7448528931f85bcb3a5835",
       "version_major": 2,
       "version_minor": 0
      },
      "text/plain": [
       "HBox(children=(IntProgress(value=0, max=1), HTML(value='')))"
      ]
     },
     "metadata": {},
     "output_type": "display_data"
    },
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "[Iter-14 Loss-0.891]:\n",
      "  Validation: normalized_discounted_cumulative_gain@3(0.0): 0.2647 - normalized_discounted_cumulative_gain@5(0.0): 0.2647 - mean_average_precision(0.0): 0.2647\n",
      "\n"
     ]
    },
    {
     "data": {
      "application/vnd.jupyter.widget-view+json": {
       "model_id": "89a99d26abc440c3a86285e8b5cf5de8",
       "version_major": 2,
       "version_minor": 0
      },
      "text/plain": [
       "HBox(children=(IntProgress(value=0, max=1), HTML(value='')))"
      ]
     },
     "metadata": {},
     "output_type": "display_data"
    },
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "[Iter-15 Loss-1.001]:\n",
      "  Validation: normalized_discounted_cumulative_gain@3(0.0): 0.2647 - normalized_discounted_cumulative_gain@5(0.0): 0.2647 - mean_average_precision(0.0): 0.2647\n",
      "\n",
      "Cost time: 6.521260976791382s\n"
     ]
    }
   ],
   "source": [
    "optimizer = torch.optim.Adam(model.parameters(), lr = 3e-4)\n",
    "\n",
    "trainer = mz.trainers.Trainer(\n",
    "    model=model,\n",
    "    optimizer=optimizer,\n",
    "    trainloader=trainloader,\n",
    "    validloader=devloader,\n",
    "    validate_interval=None,\n",
    "    epochs=15\n",
    ")\n",
    "\n",
    "trainer.run()"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 9,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "654"
      ]
     },
     "execution_count": 9,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "import gc\n",
    "gc.collect()"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {
    "collapsed": true
   },
   "outputs": [],
   "source": []
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {
    "collapsed": true
   },
   "outputs": [],
   "source": []
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {
    "collapsed": true
   },
   "outputs": [],
   "source": []
  }
 ],
 "metadata": {
  "kernelspec": {
   "display_name": "Python 3",
   "language": "python",
   "name": "python3"
  },
  "language_info": {
   "codemirror_mode": {
    "name": "ipython",
    "version": 3
   },
   "file_extension": ".py",
   "mimetype": "text/x-python",
   "name": "python",
   "nbconvert_exporter": "python",
   "pygments_lexer": "ipython3",
   "version": "3.6.3"
  }
 },
 "nbformat": 4,
 "nbformat_minor": 2
}
